home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-04
/
bipl.zip
/
PROCS.ZIP
/
CURRENCY.ICN
< prev
next >
Wrap
Text File
|
1992-11-20
|
1KB
|
40 lines
############################################################################
#
# File: currency.icn
#
# Subject: Procedures to format currency
#
# Author: Robert J. Alexander
#
# Date: December 5, 1989
#
###########################################################################
#
# currency() -- Formats "amount" in standard American currency format.
# "amount" can be a real, integer, or numeric string. "width" is the
# output field width, in which the amount is right adjusted. The
# returned string will be longer than "width" if necessary to preserve
# significance. "minus" is the character string to be used for
# negative amounts (default "-"), and is placed to the right of the
# amount.
#
############################################################################
procedure currency(amount,width,minus)
local sign,p
/width := 0
/minus := "-"
amount := real(amount) | fail
if amount < 0 then {
sign := minus
amount := -amount
}
else sign := repl(" ",*minus)
amount := string(amount)
amount := if p := find(".",amount) then left(amount,p + 2,"0") else
amount || ".00"
if match("0.",amount) then amount[1:3] := "0."
amount := "$" || amount || sign
return if *amount >= width then amount else right(amount,width)
end